package com.wutuo.tag.provider.dao;

import com.wutuo.tag.provider.domain.Tag;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author lvh
 * @version 1.0
 */
public class BaseTagSqlProvider implements java.io.Serializable {

    public String insertSelective(Tag record) {
        BEGIN();
        INSERT_INTO("tag");
        insertKey(record);
        return SQL();
    }

    public void insertKey(Tag record) {

        if (record.getTagName() != null) {
            VALUES("tag_name", "#{tagName,jdbcType=VARCHAR}");
        }
        if (record.getTagType() != null) {
            VALUES("tag_type", "#{tagType,jdbcType=BIGINT}");
        }
        if (record.getCmInstitutionId() != null) {
            VALUES("cm_institution_id", "#{cmInstitutionId,jdbcType=BIGINT}");
        }
        if (record.getTagDescribe() != null) {
            VALUES("tag_describe", "#{tagDescribe,jdbcType=VARCHAR}");
        }
        if (record.getCreateBy() != null) {
            VALUES("create_by", "#{createBy,jdbcType=BIGINT}");
        }
        if (record.getCreateDate() != null) {
            VALUES("create_date", "#{createDate,jdbcType=DATE}");
        }
        if (record.getUpdateBy() != null) {
            VALUES("update_by", "#{updateBy,jdbcType=BIGINT}");
        }
        if (record.getUpdateDate() != null) {
            VALUES("update_date", "#{updateDate,jdbcType=DATE}");
        }
        if (record.getRemarks() != null) {
            VALUES("remarks", "#{remarks,jdbcType=VARCHAR}");
        }
        if (record.getDelFlag() != null) {
            VALUES("del_flag", "#{delFlag,jdbcType=VARCHAR}");
        }
    }

    public String updateByPrimaryKeySelective(Tag record) {
        BEGIN();
        UPDATE("tag");
        updateKey(record);
        WHERE("id = #{id,jdbcType=BIGINT}");
        return SQL();
    }

    public void updateKey(Tag record) {
        if (record.getId() != null) {
            SET("id = #{id,jdbcType=BIGINT}");
        }
        if (record.getTagName() != null) {
            SET("tag_name = #{tagName,jdbcType=VARCHAR}");
        }
        if (record.getTagType() != null) {
            SET("tag_type = #{tagType,jdbcType=BIGINT}");
        }
        if (record.getCmInstitutionId() != null) {
            SET("cm_institution_id = #{cmInstitutionId,jdbcType=BIGINT}");
        }
        if (record.getTagDescribe() != null) {
            SET("tag_describe = #{tagDescribe,jdbcType=VARCHAR}");
        }
        if (record.getCreateBy() != null) {
            SET("create_by = #{createBy,jdbcType=BIGINT}");
        }
        if (record.getCreateDate() != null) {
            SET("create_date = #{createDate,jdbcType=DATE}");
        }
        if (record.getUpdateBy() != null) {
            SET("update_by = #{updateBy,jdbcType=BIGINT}");
        }
        if (record.getUpdateDate() != null) {
            SET("update_date = #{updateDate,jdbcType=DATE}");
        }
        if (record.getRemarks() != null) {
            SET("remarks = #{remarks,jdbcType=VARCHAR}");
        }
        if (record.getDelFlag() != null) {
            SET("del_flag = #{delFlag,jdbcType=VARCHAR}");
        }
    }
}